package cn.wx.scholar.core.service;

import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import cn.wx.scholar.core.entity.TxtAuthors;
import cn.wx.scholar.core.entity.qo.TxtAuthorsQ;
import cn.wx.common.persistence.base.BaseService;
import cn.wx.scholar.core.mapper.TxtAuthorsMapper;



/**
 * <p>
 *  服务类
 * </p>
 *
 * @author  
 * @since 2018-08-25
 */
@Service
@Transactional
public class TxtAuthorsService extends BaseService<TxtAuthors, TxtAuthorsMapper> {
	
	
	/**
	 * 先从redis中获取
	 * 获取不到 从数据中获取
	 * @return
	 */
	public Long uniqueIdWtihTat(TxtAuthorsQ txtAuthorsQ) {
		
		if(txtAuthorsQ == null) {
			return null;
		}
		
		//final String no = txtAuthorsQ.getName() + txtAuthorsQ.getAffiliation();
		//final String md5no = MD5Util.MD5(no);
		
		/**
		 * 从redis中获取
		 */
		//RMapCache<String,Long> map = redissonClient.getMapCache("TXT_AUTHORS_SAPCE");
		//Long pId = map.get(md5no);
		
		//if(pId == null) {
		Long pId = super.simpleMapper.queryUniqueWtihTat(txtAuthorsQ);
		//}

		if(pId == null) {
			TxtAuthors txtAuthors = new TxtAuthors();
			
			txtAuthors.setName(txtAuthorsQ.getName());
			txtAuthors.setAffiliation(txtAuthorsQ.getAffiliation());
			
			super.simpleMapper.insertUniqueWtihTat(txtAuthors);
			
			return txtAuthors.getpId();
		}
		
		//map.put(md5no, pId, 30, TimeUnit.MINUTES);
		return pId;
	}
	
	/**
	 * 插入专家
	 * @param txtAuthors
	 */
	public boolean insertWtihTat(String tat,List<TxtAuthors> tas) {
		try {
			super.simpleMapper.insertWtihTat(tat,tas);
			return true;
		}catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
	
}
